package com.assets.asset.annotation.aop;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.assets.asset.mapper.TReturnMapper;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 这个是退库表的
 * 用aop将存所属公司的id号转换为公司名
 * 以及将资产表中的是否退库状态转变
 */
@Aspect
@Component
public class ReturnComIdAndStatusAOP {


    @Autowired
    private TReturnMapper tReturnMapper;


    @Around("@annotation(com.assets.asset.annotation.ReturnComIdAndStatus)")
//    public void around(JoinPoint point) throws Throwable {
    public Object around(ProceedingJoinPoint point) throws Throwable {


        //获取当前
//        Object[] args = joinPoint.getArgs();
        Object[] args = point.getArgs();

        Object result = point.proceed(args);

        String toJSONString = JSON.toJSONString(args);
        System.out.println("toJSONString = " + toJSONString);


        String s = toJSONString.replace("]", "");
        String replace = s.replace("[", "");
        System.out.println(replace);

        JSONObject jsonObject = JSON.parseObject(replace);
        String assetCode = jsonObject.getString("assetCode");

        //转ID
        tReturnMapper.updateCom(assetCode);

        //赋予退库状态，资产状态也为闲置
        tReturnMapper.returnAsset(assetCode);


        return result;

    }


}
